<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>友链管理</title>
<link rel="stylesheet" type="text/css" href="<%=basePath %>/admin/css/easyui.css">
<link rel="stylesheet" type="text/css" href="<%=basePath %>/admin/css/icon.css">
<script type="text/javascript" src="<%=basePath %>/admin/js/jquery-1.7.1.js"></script>
<script type="text/javascript" src="<%=basePath %>/admin/js/jquery.easyui.min.js"></script>
<script type="text/javascript" language="javascript" src="<%=basePath %>/admin/js/commom.js"></script>
<script type="text/javascript" language="javascript" src="<%=basePath %>/admin/js/operate.js"></script>
<script type="text/javascript" src="<%=basePath %>/admin/xheditor/xheditor-1.1.14-zh-cn.min.js"></script>
<script type="text/javascript" language="javascript" src="<%=basePath %>/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
	$(document).ready(
			function() {
				dataGridInfo("employer_data", "datagrid", "",
						"toolbar");
				    // Client side form validation
				    $('form').submit(function(e) {
				        var uploader = $('#uploader').pluploadQueue();
				        // Validate number of uploaded files
				        if (uploader.total.uploaded == 0) {
				            // Files in queue upload them first
				            if (uploader.files.length > 0) {
				                // When all files are uploaded submit form
				                uploader.bind('UploadProgress', function() {
				                    if (uploader.total.uploaded == uploader.files.length)
				                        $('form').submit();
				                });
				 
				                uploader.start();
				            } else
				                alert('You must at least upload one file.');
				 
				            e.preventDefault();
				        }
				    });
			});
	function editMessage() {
		var row = $('#message_data').datagrid('getSelected');
		if (row) {
			$('#dlg').dialog('open').dialog('setTitle', '查看留言');
			$("#title").get(0).value = row.title;
			$("#department").get(0).value = row.department;
			$("#address").get(0).value = row.address;
			$("#content").get(0).value = row.content;
		}
	}
	/**
	* 添加员工
	*/
	function add(){
		$("#info").val('');
		$('#dlg').dialog('open').dialog('setTitle', '添加员工');
		$('#preHeadImg').css('display','none');
		$('#preBigImg').css('display','none');
		$('#fm').form('clear');
		url = 'doAdd';
	}
	/**
	* 修改员工密码
	*/
	function editPassword() {
		var row = $('#employer_data').datagrid('getSelected');
		if (row) {
			$('#editPassword').dialog('open');
			$('#isAdmin').combobox('setValue',row.isAdmin);
		}
		
		$('#passForm').form('clear');
		url = 'doUpdatePassword';
	}
	
	function doEditPassword () {
		var row = $('#employer_data').datagrid('getSelected');
		$('#updatePasswordId').val(row.id);
		$('#passForm').form('submit',{
			url : url,
			onSubmit : function() {
				if($('#password1').val()!=$('#password2').val()){
					$.messager.alert('警告','两次输入的密码不一致!');
					return false;
				}
				return $(this).form('validate');
			},
			success : function(result) {
				var result = eval('(' + result + ')');
				if (result.errorMsg) {
					$.messager.show({
						title : 'Error',
						msg : result.errorMsg
					});
				} else {
					$('#editPassword').dialog('close'); // close the dialog
					$('#employer_data').datagrid('reload'); // reload the user data
				}
			}
		});
	}
	/**
   	* 提交表单
	*/
	function saveEmployer(){
		$('#fm').form('submit', {
			url : url,
			data : {info:$('#info').val()},
			onSubmit : function() {
				return $(this).form('validate');
			},
			success : function(result) {
				var result = eval('(' + result + ')');
				if (result.errorMsg) {
					$.messager.show({
						title : 'Error',
						msg : result.errorMsg
					});
				} else {
					$('#dlg').dialog('close'); // close the dialog
					$('#employer_data').datagrid('reload'); // reload the user data
				}
			}
		});
	}
	/**
	* 删除员工
	*/
	function destory(){
		var row = $('#employer_data').datagrid('getSelected');
		if(row) {
			$.messager.confirm('Confirm','你确定要删除选中的数据吗?',function(r){
				if(r){
					$.post('doDelete',{id:row.id},function(result){
						if(result.errorMsg){
							$.messager.show({
								title : '错误',
								msg : result.errorMsg
							});
						} else {
							$('#employer_data').datagrid('reload');
						}
					});
				}
			});
		} else {
			$.messager.show({
				title : '提示信息',
				msg : '请选择要操作的数据!'
			});
		}
	}
	
	function edit(){
		var row = $('#employer_data').datagrid('getSelected');
		if (row) {
			$('#fm').form('clear');
			$.post('goUpdate',{id:row.id},function(result){
				if(result.errorMsg) {
					$.messager.show({
						title : 'Error',
						msg : result.errorMsg
					});
				} else {
					$('#dlg').dialog('open').dialog('setTitle', '修改员工信息');
					$('#fm').form('load', result);
					$('#parentId').combobox('setValue',result.parentId);
					$('#preHeadImg').attr('src',$('#picUrl').val());
					$('#preBigImg').attr('src',$('#bigPicUrl').val());
					$("#info").val($('#infoTextValue').val());
				}
			});
			url = 'doUpdate?department.id=' + row.id;
		}
	}
	
</script>
</head>
<body>
	<div class="easyui-panel" data-options="fit:true" style='border: none'>
		<div class="easyui-layout" data-options="fit:true"
			style='border: none'>
			<div id='sss' data-options="region:'center'" style='border: none'>
				<table style='border: 1px solid red' id="employer_data"
					class="easyui-datagrid">
					<thead>
						<tr>
							<th data-options="field:'id',width:30,align:'center',hidden:true">编号</th>
							<th data-options="field:'isAdmin',width:30,align:'center',hidden:true">是否为管理员</th>
							<th data-options="field:'empId',width:80,align:'center'">员工编号</th>
							<th data-options="field:'name',width:80,align:'center'">姓名</th>
							<th data-options="field:'position',width:160,align:'center',hidden:true">职位</th>
							<th data-options="field:'positionName',width:160,align:'center'">职位名称</th>
							<th data-options="field:'departmentId',width:160,align:'center',hidden:true">所属部门ID</th>
							<th data-options="field:'departmentName',width:120,align:'center'">所属部门</th>
							<th data-options="field:'username',width:120,align:'center'">用户名</th>
							<th data-options="field:'lastLoginDate',width:80,align:'center'">最后一次登陆时间</th>
							<th data-options="field:'loginTimes',width:120,align:'center'">登陆次数</th>
						</tr>
					</thead>
				</table>
				<div id="toolbar">
					<a href="javascript:void(0)" class="easyui-linkbutton"
						iconCls="icon-add" plain="true" onclick="add()">添加员工</a>
					<a href="javascript:void(0)" class="easyui-linkbutton"
						iconCls="icon-remove" plain="true" onclick="destory()">删除员工</a>
					<a href="javascript:void(0)" class="easyui-linkbutton"
						iconCls="icon-edit" plain="true" onclick="edit()">修改员工</a>
					<a href="javascript:void(0)" class="easyui-linkbutton"
						iconCls="icon-edit" plain="true" onclick="editPassword()">修改密码</a>
				</div>
				
				<div id="editPassword" class="easyui-dialog"
					style="width: 800px; height: 600px; padding: 10px 20px"
					closed="true" buttons="#dlg-buttons">
					<div class="ftitle">修改密码</div>
					<form id="passForm" method="post">
						<div class="fitem">
							<label>设置密码:</label> 
							<input id="updatePasswordId" name="updatePasswordId" type="hidden">
							<input id='password1' name="password1" type="password" required="true" maxlength="16" style='width:270px;'>
						</div>
						<div class="fitem">
							<label>确定密码:</label> 
							<input id='password2' name="password2" type="password" required="true" maxlength="16" style='width:270px;'>
						</div>
						<div class="fitem">
							<label>是否为管理员:</label> 
							<input id="isAdmin" name="isAdmin" required="true" class="easyui-combobox" style="width:80px;"
								data-options="valueField:'value',textField:'text',data:[{value:'0',text:'否'},{value:'1',text:'是'}]">
						</div>
						<div id="dlg-buttons">
							<a href="javascript:void(0)" class="easyui-linkbutton c6"
							   iconCls="icon-ok" onclick="doEditPassword()" style="width: 90px">确定</a>
							<a href="javascript:void(0)" class="easyui-linkbutton" 
							   iconCls="icon-cancel" onclick="javascript:$('#editPassword').dialog('close')">取消</a>
						</div>
					</form>
				</div>
				
				<div id="dlg" class="easyui-dialog"
					style="width: 800px; height: 600px; padding: 10px 20px"
					closed="true" buttons="#dlg-buttons">
					<div class="ftitle">员工信息</div>
					<form id="fm" method="post"  enctype="multipart/form-data">
						<div class="fitem">
							<label>员工编号:</label> 
							<input id="id" name="employer.id" type="hidden">
							<input id='empId' name="employer.empId" type='text' required="true" style='width:270px;'>
						</div>
						<div class="fitem">
							<label>头像:</label>
							<input name="headImg.id" type="hidden">
							<input name="headImg.dataType" type="hidden">
							<input name="headImg.seat" type="hidden">
							<input name="headImg.downloadTimes" type="hidden">
							<input name="headImg.watchTimes" type="hidden">
							<input name="headImg.picUrl" type="hidden" id="picUrl">
							<input name="headImg.owner" type="hidden">
							<input id='handImg' name="handImg" type='file' required="true" readonly="readonly"
								onchange="previewImage(this,'preHead','preHeadImg','picUrl')">
						</div>
						<div class="fitem" id="preHead">
							<label>预览</label>
							<img id="preHeadImg" width=100 height=100 border=0 src='<%=request.getContextPath()%>/images/defaul.jpg'>
						</div>
						<div class="fitem">
							<label>大图像:</label> 
							<input name="bigImg.id" type="hidden">
							<input name="bigImg.dataType" type="hidden">
							<input name="bigImg.seat" type="hidden">
							<input name="bigImg.downloadTimes" type="hidden">
							<input name="bigImg.watchTimes" type="hidden">
							<input name="bigImg.picUrl" type="hidden" id="bigPicUrl">
							<input name="bigImg.owner" type="hidden">
							<input id='bigImg' name="bigImg" type='file' required='true' readonly='readonly'
								onchange="previewImage(this,'preBig','preBigImg', 'bigPicUrl')">
						</div>
						<div class="fitem" id="preBig">
							<label>预览</label>
							<img id="preBigImg" width=100 height=100 border=0 src='<%=request.getContextPath()%>/images/defaul.jpg'>
						</div>
						<div class="fitem">
							<label>姓名:</label> 
							<input id='name' name="employer.name" type='text' required="true" style='width:270px;'>
						</div>
						<div class="fitem">
							<label>出生年月:</label> 
							<input id='birthdate' name="employer.birthdate" required="true" readonly="readonly" type='text' style='width:270px;' onClick="WdatePicker()">
						</div>
						<div class="fitem">
							<label>性别:</label> 
							<select id='sex' name="employer.sex" required="true" class="easyui-combobox" style='width:270px;'>
								<option value='0'>男</option>
								<option value='1'>女</option>
							</select>
						</div>
						<div class="fitem">
							<label>手机号码:</label> 
							<input id='phone' name="employer.phone" required="true" type='text' style='width:270px;'>
						</div>
						<div class="fitem">
							<label>邮箱:</label> 
							<input id='title' name="employer.email" required="true" type='text' validType="email" style='width:270px;'>
						</div>
						<div class="fitem">
							<label>所属部门:</label> 
							<input id="departmentId" name="employer.departmentId" required="true" class="easyui-combobox" style="width:270px;"
								data-options="valueField:'id',textField:'name',url:'department/searchAllDept'">
						</div>
						<div class="fitem">
							<label>入职时间:</label> 
							<input id='joinTime' name="employer.joinTime" required="true" readonly="readonly" type='text' style='width:270px;' onClick="WdatePicker()">
						</div>
						<div class="fitem">
							<label>用户名:</label> 
							<input id='username' name="employer.username" required="true" type='text' style='width:270px;'>
						</div>
						<div class="fitem">
							<label>职位:</label> 
							<input id='position' name="employer.position" required="true" class="easyui-combobox" style='width:270px;'
								data-options="valueField:'id',textField:'name',url:'position/getComboboxValue'">
						</div>
						<div class="fitem">
							<label>员工介绍:</label> 
							<input name="info.id" type="hidden">
							<input name="info.dataType" type="hidden">
							<input name="info.textValue" type="hidden" id="infoTextValue">
							<input name="info.seat" type="hidden">
							<input name="info.downloadTimes" type="hidden">
							<input name="info.watchTimes" type="hidden">
							<input name="info.owner" type="hidden">
							<textarea id='info' name="info" class="xheditor" style='width:450px;height:140px'></textarea>
						</div>
					</form>
				</div>
				<div id="dlg-buttons">
					<a href="javascript:void(0)" class="easyui-linkbutton c6"
					   iconCls="icon-ok" onclick="saveEmployer()" style="width: 90px">确定</a>
					<a href="javascript:void(0)" class="easyui-linkbutton" 
					   iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
				</div>
			</div>
		</div>
	</div>
</body>
</html>